package com.itheima.vo;

import cn.hutool.core.util.ObjectUtil;
import com.itheima.domain.db.UserInfo;
import com.itheima.domain.mongo.Sound;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;



@Data
@NoArgsConstructor
@AllArgsConstructor
public class SoundVo implements Serializable {
    private Long id; //用户id
    private String nickname; //昵称
    private String avatar; //用户头像
    private String gender; //性别
    private Integer age; //年龄
    private String soundUrl; //语音地址
    private Integer remainingTimes; //剩余次数

    public static SoundVo init(UserInfo userInfo, Sound sound, Integer remainingTimes){
        if (ObjectUtil.isEmpty(userInfo)){
            return null;
        }
        SoundVo soundVo = new SoundVo();
        BeanUtils.copyProperties(userInfo, soundVo);
        soundVo.setSoundUrl(sound.getSoundUrl());
        soundVo.setRemainingTimes(remainingTimes);
        return soundVo;
    }
}
